new operator vs newInstance() method in Java ?
new operator vs newInstance() method
865
25-Jun-2018
Prakash nidhi Verma
26-Jun-2018new operator vs newInstance() method in Java:
new operator is used to create objects but when you wants to create that in runtime thats no way you can use new operator. you have to use newInstance() method in this case.
// Java program to demonstrate working of newInstance()
Class.forName() method return class object on which we are calling newInstance() method. If the class doesn’t exist then ClassNotFoundException will occur. InstantionException will occur if the class doesn’t receive any default constructor as newInstance() method.